home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / MPW / gzip 1.2.2 / znew.mac < prev   
Encoding:
Text File  |  1993-07-11  |  3.3 KB  |  168 lines  |  [TEXT/MPS ]

  1. #
  2. # znew.mac -- znew for MPW
  3. #
  4. # written by Anthony C. Ard, 1993
  5. #
  6. # this script requires sed
  7. #
  8.  
  9. set exit 0
  10. set check 0
  11. set pipe 0
  12. unset opt
  13. unset files
  14. set keep 0
  15. set res 0
  16. set old 0
  17. set new 0
  18. set block 1024
  19. # block is the disk block size (best guess, need not be exact)
  20.  
  21. set warn "(does not preserve modes and timestamp)"
  22. set tmp "{TempFolder}"zfoo
  23.  
  24. echo "hi" >"{tmp}.1"
  25. echo "hi" >"{tmp}.2"
  26.  
  27. # check if GZIP env. variable uses -S or --suffix
  28. gzip -q "{tmp}".1
  29. set ext `files "{tmp}".1≈ | sed "s|{tmp}.1||"`
  30. delete -y "{tmp}".[12]≈
  31.  
  32. if "{ext}" == ""
  33.     echo "znew: error determining gzip extension."
  34.     set exit 1
  35.     exit 1
  36. end
  37.  
  38. if "{ext}" == ".Z"
  39.     echo "znew: cannot use .Z as gzip extension."
  40.     set exit 1
  41.     exit 1
  42. end
  43.  
  44. unset A
  45. set fileno 0
  46.  
  47. for arg in {Parameters}
  48.     if "{arg}" =~ /-≈/
  49.         set opt "{opt} {arg}"
  50.     else
  51.         set fileno `evaluate {fileno} + 1`
  52.         set A "{A} {arg}"
  53.     end
  54. end
  55.  
  56. if {fileno} == 0
  57.     echo "recompress .Z files into {ext} (gzip) files"
  58.     echo usage: `echo {0} | sed 's,^.*/,,'` "[-tv9KP] file.Z…"
  59.     echo "  -t tests the new files before deleting originals"
  60.     echo "  -v be verbose"
  61.     echo "  -9 use the slowest compression method (optimal compression)"
  62.     echo "  -K keep a .Z file when it is smaller than the {ext} file"
  63.     echo "  -P use pipes for the conversion {warn}"
  64.     set exit 1
  65.     exit 1
  66. end
  67.  
  68. set opt `echo "{opt}" | sed -e 's/ //g' -e 's/-//g'`
  69.  
  70. if "{opt}" =~ /≈t≈/
  71.     set check 1
  72.     set opt "`echo {opt} | sed 's/t//g'`"
  73. else if "{opt}" =~ /≈K≈/
  74.     set keep 1
  75.     set opt "`echo {opt} | sed 's/K//g'`"
  76. else if "{opt}" =~ /≈P≈/
  77.     set pipe 1
  78.     set opt "`echo {opt} | sed 's/P//g'`"
  79. end
  80.  
  81. if "{opt}" != ""
  82.     set opt "-{opt}"
  83. end
  84.  
  85. for i in {A}
  86.     set n "`echo "{i}" | sed 's/.Z$//'`"
  87.     if !`exists -f "{n}.Z"`
  88.         echo "{n}.Z not found"
  89.         set res 1
  90.         continue
  91.     end
  92.     if {keep} == 1
  93.         set old `count -c <"{n}.Z"`
  94.     end
  95.     if {pipe} == 1
  96.         gzip -d <"{n}.Z" | gzip {opt} >"{n}{ext}"
  97.         if {Status} == 0
  98.             # Copy file attributes from old file to new one, if possible.
  99.         else
  100.             echo "error while recompressing {n}.Z."
  101.             set res 1
  102.             continue
  103.         end
  104.     else
  105.         if {check} == 1
  106.             cp "{n}.Z" "{n}.xxx" ≥Dev:Null
  107.             if {Status} != 0
  108.                 echo "cannot backup {n}.Z"
  109.                 set res 1
  110.                 continue
  111.             end
  112.         end
  113.         gzip -d "{n}.Z"
  114.         if {Status} != 0
  115.             if {check} == 1
  116.                 duplicate -y "{n}.xxx" "{n}.Z"
  117.             end
  118.             echo "error while uncompressing "{n}.Z"
  119.             set res 1
  120.             continue
  121.         end
  122.         gzip {opt} "{n}"
  123.         if {Status} != 0
  124.             if {check} == 1
  125.                 duplicate -y "{n}.xxx" "{n}.Z" && delete "{n}"
  126.                 echo "error while recompressing {n}"
  127.             else
  128.                 # compress {n} (might be dangerous if disk full)
  129.                 echo "error while recompressing {n}, left uncompressed."
  130.             end
  131.             set res 1
  132.             continue
  133.         end
  134.     end
  135.     if {keep} == 1
  136.         set new `count -c <"{n}{ext}"`
  137.     end
  138.     if {keep} == 1 && `evaluate ({old}+{block}-1)÷{block}` < ∂
  139.                       `evaluate ({new}+{block}-1)÷{block}`
  140.         if {pipe} == 1
  141.             delete -y "{n}{ext}"
  142.         else if {check} == 1
  143.             duplicate -y "{n}.xxx" "{n}.Z" && delete -y "{n}{ext}"
  144.         else
  145.             gzip -d "{n}{ext}" && compress "{n}" && delete -y "{n}{ext}"
  146.         end
  147.         echo "{n}.Z smaller than {n}{ext} -- unchanged."
  148.     else if {check} == 1
  149.         gzip -t "{n}{ext}
  150.         if {Status} == 0
  151.             delete -y "{n}.xxx" "{n}.Z"
  152.         else
  153.             if {pipe} == 0
  154.                 duplicate -y "{n}.xxx" "{n}.Z"
  155.             end
  156.             delete -y "{n}{ext}"
  157.             echo "error while testing {n}{ext}, {n}.Z unchanged."
  158.             set res 1
  159.             continue
  160.         end
  161.     else if {pipe} == 1
  162.         delete -y "{n}.Z"
  163.     end
  164. end
  165.  
  166. set exit 1
  167. exit {res}
  168.